package com.example.controller;

import com.example.common.Result;
import com.example.entity.FlClient;
import com.example.service.FLClientService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/flclient")
public class FLClientController {

    @Resource
    private FLClientService flClientService;

    /**
     * 新增客户端
     */
    @PostMapping("/add")
    public Result add(@RequestBody FlClient flClient) {
        flClientService.add(flClient);
        return Result.success("Client added successfully");
    }

    /**
     * 删除客户端
     */
    @DeleteMapping("/delete/{clientId}")
    public Result deleteById(@PathVariable String clientId) {
        flClientService.deleteByClientId(clientId);
        return Result.success("Client deleted successfully");
    }

    /**
     * 更新客户端信息
     */
    @PostMapping("/update")
    public Result updateById(@RequestBody FlClient flClient) {
        flClientService.update(flClient);
        return Result.success("Client updated successfully");
    }

    /**
     * 根据ID查询客户端
     */
    @GetMapping("/selectByClientIdAndTaskId")
    public Result selectByClientIdAndTaskId(@RequestParam String clientId, @RequestParam String taskid) {
        FlClient client = flClientService.getByClientIdAndTaskId(clientId, taskid);
        if (client != null) {
            return Result.success(client);
        } else {
            return Result.error("202", "Client not found");
        }
    }


    /**
     * 查询所有客户端
     */
    @GetMapping("/selectAll")
    public Result selectAll(FlClient flClient) {
        return Result.success(flClientService.getAll(flClient));
    }
}